package com.fr.data.util.function;

import com.fr.base.FComparator;
import com.fr.base.core.ComparatorUtils;
import com.fr.data.util.DefaultComparator;
import com.fr.report.script.Primitive;

public class MinFunction extends AbstractDataFunction
{
  private FComparator comparator;
  private Object minResult;

  public MinFunction()
  {
    this(null);
  }

  public MinFunction(FComparator paramFComparator)
  {
    this.comparator = null;
    this.minResult = new Double(1.7976931348623157E+308D);
    if (paramFComparator == null)
      paramFComparator = new DefaultComparator();
    setComparator(paramFComparator);
    reset();
  }

  public FComparator getComparator()
  {
    return this.comparator;
  }

  public void setComparator(FComparator paramFComparator)
  {
    this.comparator = paramFComparator;
  }

  public void reset()
  {
    this.minResult = null;
  }

  public void addData(Object paramObject)
  {
    if ((paramObject == null) || (ComparatorUtils.equals(Primitive.NULL, paramObject)))
      return;
    if (this.minResult == null)
    {
      this.minResult = paramObject;
      return;
    }
    int i = this.comparator.compare(this.minResult, paramObject);
    if (i > 0)
      this.minResult = paramObject;
  }

  public Object getResult()
  {
    return this.minResult;
  }

  public String getFormula()
  {
    return "min";
  }
}